#include "stdafx.h"

#pragma  comment(lib,"wsock32.lib")

#ifdef _ATL_STATIC_REGISTRY
#include <statreg.h>
#include <statreg.cpp>
#endif

#include <atlimpl.cpp>


Cw2c::Cw2c()
{
	p=NULL;
}

Cw2c::~Cw2c()
{
	if(p)free(p);
}

void Cw2c::in(BSTR str)
{
	int len;
	if(p)free(p);
	len=WideCharToMultiByte(CP_ACP,0,str,-1,NULL,0,NULL,NULL);
	p=(char *)malloc(len);
	WideCharToMultiByte(CP_ACP,0,str,-1,p,len,NULL,NULL);
}

char *Cw2c::out()
{
	return p;
}

Cc2w::Cc2w()
{
	p=NULL;
}

Cc2w::~Cc2w()
{
	if(p)SysFreeString(p);
}

void Cc2w::in(LPCTSTR str)
{
	int len;
	if(p)SysFreeString(p);
	len=MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,str,-1,NULL,0);
	p=SysAllocStringLen(NULL,len);
	MultiByteToWideChar(CP_ACP,MB_PRECOMPOSED,str,-1,p,len);
}

BSTR Cc2w::out()
{
	return p;
}
